package com.littlerpc.protocol.net.common;


import com.littlerpc.protocol.codec.Serializer;
import com.littlerpc.protocol.codec.json.JacksonSerializer;
import com.littlerpc.protocol.codec.protobuf.ProtobufSerializer;

/**
 *
 * @author ChengPeng
 * @date 2017/6/19
 */
public enum SerializerEnum {
    /**
     * jascson序列化
     */
    JACKSON(new JacksonSerializer()),
    /**
     * protobuf 序列化
     */
    PROTOBUF(new ProtobufSerializer());

    public final Serializer serializer;

    SerializerEnum(Serializer serializer) {
        this.serializer = serializer;
    }

    private Serializer value() {
        return serializer;
    }

    public static Serializer match(String name){

        if(name == null || "".equals(name)) {
            return JACKSON.value();
        }

        for (SerializerEnum item : SerializerEnum.values()) {
            if (item.name().equalsIgnoreCase(name)) {
                return item.value();
            }
        }
        return JACKSON.value();
    }
}
